package player;

import character.MyCharacter;
import game.GameUtil;
import game.PlayerRelationship;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import misc.Vector3i;

public abstract class Player {
    protected int id;
    protected String name;
    protected List<MyCharacter> characters = new LinkedList<MyCharacter>();
    protected Set<Vector3i> visibleLocations = new HashSet<Vector3i>();
    protected Map<Player, PlayerRelationship> relationships = new HashMap<Player, PlayerRelationship>();

    @Deprecated
    protected Player() {}

    public Player(String name) {
	id = GameUtil.getNextPlayerId();
	this.name = name;
    }

    public int getId() {
	return id;
    }
    public String getName() {
	return name;
    }
    public void setName(String name) {
	this.name = name;
    }
    public Collection<MyCharacter> getCharacters() {
	return characters;
    }
    public void addCharacter(MyCharacter character) {
	characters.add(character);
    }
    public void removeCharacter(MyCharacter character) {
	characters.remove(character);
    }
    public Set<Vector3i> getVisibleLocations() {
	return visibleLocations;
    }
    public void updateVisibleLocations() {
	visibleLocations.clear();
	for(MyCharacter character : characters)
	    visibleLocations.addAll(character.getVisibleLocations());
    }
    public PlayerRelationship getRelationship(Player player) {
        return relationships.get(player);
    }
    public void addRelationship(Player player, PlayerRelationship teamRelationship) {
        relationships.put(player, teamRelationship);
    }

    @Override
    public boolean equals(Object obj) {
	if (obj == null) {
	    return false;
	}
	if (getClass() != obj.getClass()) {
	    return false;
	}
	final Player other = (Player) obj;
	if (this.id != other.id) {
	    return false;
	}
	return true;
    }

    @Override
    public int hashCode() {
	int hash = 5;
	hash = 29 * hash + this.id;
	return hash;
    }
}
